package com.dxt.springmvcdemo.utils;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 * BelongProject: springMVC
 * BelongPackage: com.dxt.springmvcdemo.utils
 * Description:
 *
 * @Author 段鑫涛
 * @Create 2025/4/14 19:29
 * @Version 1.0
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class R<T> {
    @Schema(description = "状态码")
    private Integer code;
    @Schema(description = "返回信息")
    private String message;
    @Schema(description = "返回数据")
    private T data;

    public static <T> R<T> success(){
        return new R<>(200,"success",null);
    }

    public static <T> R<T> success(T data){
        return new R<>(200,"success",data);
    }

    public static <T> R<T> success(Integer code, String message){
        R<T> r = new R<>();
        r.setCode(code);
        r.setMessage(message);
        r.setData(null);
        return r;
    }
    public static <T> R<T> success(Integer code, String message, T data){
        R<T> r = new R<>();
        r.setCode(code);
        r.setMessage(message);
        r.setData(data);
        return r;
    }

    public static <T> R<T> error(Integer code, String message){
        R<T> r = new R<>();
        r.setCode(code);
        r.setMessage(message);
        r.setData(null);
        return r;
    }

    public static <T> R<T> error(Integer code, String message, T data){
        R<T> r = new R<>();
        r.setCode(code);
        r.setMessage(message);
        r.setData(data);
        return r;
    }
}
